package com.woniuxy.lab.woniu_lab.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.lab.woniu_lab.model.Range;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniuxy.lab.woniu_lab.service.dto.BaseDto;
import com.woniuxy.lab.woniu_lab.service.dto.markDto.UserMarkDto;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 靶场表 Mapper 接口
 * </p>
 *
 * @author Silas
 * @since 2023-03-15
 */
public interface RangeDao extends BaseMapper<Range> {

    @Select("SELECT *\n" +
            "FROM lab_range lr\n" +
            "WHERE lr.id IN (SELECT range_id FROM lab_mark WHERE user_id = #{userId}) AND lr.ctf_or_exper = 'exper'"+
            " ORDER BY lr.upload_time DESC")
    IPage<UserMarkDto> queryMyMark(@Param("userId") Integer userId,@Param("iPage") IPage<UserMarkDto> iPage);

    @Select("SELECT *\n" +
            "FROM lab_range lr\n" +
            "WHERE lr.id IN (SELECT range_id FROM lab_mark WHERE user_id = #{userId})\n" +
            "AND lr.ctf_or_exper = 'ctf'\n" +
            "ORDER BY lr.upload_time DESC")
    IPage<UserMarkDto> queryMyCTF(@Param("userId") Integer userId,@Param("iPage") IPage<UserMarkDto> iPage);

    @Select("SELECT lb.*,lbr.l_path,lbr.c_path,lbr.env\n" +
            "FROM lab_base_range lbr\n" +
            "JOIN lab_base lb\n" +
            "on lbr.base_id = lb.id\n" +
            "WHERE lbr.range_id = #{rangeId}}")
    List<BaseDto> getBaseInfo(Integer rangeId);
}
